package com.example.autopia.view.ViewHolders.MyCars

import android.view.LayoutInflater
import android.view.animation.AnimationUtils
import androidx.recyclerview.widget.RecyclerView
import com.example.autopia.R
import com.example.autopia.databinding.ViewholderMyCarsBinding
import com.example.autopia.databinding.ViewholderTransactionActiveBinding
import com.example.autopia.model.Item.Car
import com.example.autopia.model.Item.Transaction
import com.example.autopia.view.Listeners.MyCarsListener

class MyCarViewHolder  (private val binding: ViewholderMyCarsBinding, private val inflater: LayoutInflater) :
    RecyclerView.ViewHolder(binding.root) {

    fun bind(car: Car, listener: MyCarsListener){

        binding.apply {
            tvModel.text = car.model
            tvColor.text = getColor(car.color)
            tvNumber.text = car.number
        }

        val address = "car_user_"+car.color
        val resourceId = inflater.context.resources.getIdentifier(address,"drawable",inflater.context.packageName)
        binding.ivCar.setBackgroundResource(resourceId)

        binding.btEdit.setOnClickListener {
            listener.onEditClicked(car,false)
        }

        val animation = AnimationUtils.loadAnimation(inflater.context, R.anim.fade_in)
        binding.root.startAnimation(animation)
    }
    private fun getColor(color:String) : String{
        return when(color){
            "black"-> "Чёрный"
            "red"-> "Красный"
            "orange"-> "Оранжевый"
            "yellow"-> "Жёлтый"
            "green"-> "Зелёный"
            "blue_light"-> "Голубой"
            "blue"-> "Синий"
            "purple"-> "Фиолетовый"
            "pink"-> "Розовый"
            "brown"-> "Коричневый"
            "grey"-> "Серый"
            "white"-> "Белый"
            else-> "Белый"
        }
    }
}